home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.08 Aug 91 / Dots Source / cDotsApp.c next >
Encoding:
C/C++ Source or Header  |  1989-11-04  |  2.7 KB  |  118 lines  |  [TEXT/KAHL]

  1. /****************************
  2.  
  3.     cDotsApp.c
  4.  
  5.     SUPERCLASS = CApplication
  6.     
  7. Application methods for Dots
  8.  
  9. *****************************/
  10.  
  11. #include <CError.h>
  12. #include <Commands.h>
  13. #include <Constants.h>
  14. #include "cDotsApp.h"
  15. #include "cDotsDoc.h"
  16. #include "dotsTypes.h"
  17.  
  18. /*** Class Constants ***/
  19. #define        I_ABOUT        8    /* String index in STRcommon */
  20.  
  21.  
  22. /*** Globals ***/
  23. extern    CError    *gError;        /* The global error handler */
  24. extern    OSType    gSignature;        /* File creator signature */
  25.  
  26. extern    Pattern    *dgPlayerPats;
  27.  
  28. /********** I N I T I A L I Z A T I O N ********/
  29.  
  30. /*** IDotsApp
  31. *
  32. * Initialize the application. Your initialization method should
  33. * at least call the inherited method. If your application class
  34. * defines its own instance variables or global variables, this
  35. * is a good place to initialize them.
  36. */
  37. void cDotsApp::IDotsApp(void)
  38. {
  39.         /* Set moreMasters, rainyDayFund, creditLimit */
  40.     CApplication::IApplication(4, 20480L, 2048L);
  41.     
  42.         /* Set the patterns associated with each player */
  43.     BlockMove(ltGray, &dgPlayerPats[kPlayer1], sizeof(Pattern));
  44.     BlockMove(dkGray, &dgPlayerPats[kPlayer2], sizeof(Pattern));
  45. }
  46.  
  47.  
  48. /*** SetUpFileParameters {OVERRIDE}
  49. *
  50. * Specify the kinds of files the application opens
  51. */
  52. void cDotsApp::SetUpFileParameters(void)
  53. {
  54.     inherited::SetUpFileParameters();    /* Call the default method */
  55.  
  56.     gSignature = 'dots';    /* File creator */
  57.  
  58.         /* Set the number and types of files recognized */
  59.     sfNumTypes = 1;
  60.     sfFileTypes[0] = 'DATA';
  61. }
  62.  
  63.  
  64. /********** C O M M A N D ********/
  65.  
  66. /*** DoCommand    {OVERRIDE}
  67. *
  68. * Your application will probably handle its own commands.
  69. * Remember, the command numbers from 1-1023 are reserved.
  70. * The file Commands.h contains all the reserved commands.
  71. * Be sure to call the default method, so you can get
  72. * the default behvior for standard commands.
  73. */
  74. void cDotsApp::DoCommand(long theCommand)
  75. {
  76.     switch (theCommand) {
  77.     
  78.         case cmdAbout:
  79.             gError->PostAlert(STRcommon, I_ABOUT);    /* Show the 'about' alert */
  80.             break;
  81.         default:
  82.             inherited::DoCommand(theCommand);
  83.             break;
  84.     }
  85. }
  86.  
  87. /********** D O C U M E N T ********/
  88.  
  89. /*** CreateDocument    {OVERRIDE}
  90. *
  91. * The user chose New from the File menu. Create a document and send it
  92. * a NewFile() message.
  93. */
  94. void cDotsApp::CreateDocument()
  95. {
  96.     cDotsDoc    *theDocument;
  97.     
  98.     theDocument = new(cDotsDoc);
  99.     theDocument->IDotsDoc(this, TRUE);
  100.     theDocument->NewFile();
  101. }
  102.  
  103. /*** OpenDocument    {OVERRIDE}
  104. *
  105. * Open… was chosen from the File menu. Create a document
  106. * and send it an OpenFile() message.
  107. *
  108. * The macSFReply is a good SFReply record that contains
  109. * the name and vRefNum of the file the user chose to open.
  110. */ 
  111. void cDotsApp::OpenDocument(SFReply *macSFReply)
  112. {
  113.     cDotsDoc    *theDocument;
  114.     
  115.     theDocument = new(cDotsDoc);
  116.     theDocument->IDotsDoc(this, TRUE);
  117.     theDocument->OpenFile(macSFReply);
  118. }